<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改汉典内容')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dictspider-edit" th:object="${zdicSpider}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">字：</label>
                <div class="col-sm-8">
                    <input name="zi" th:field="*{zi}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">说源解字：</label>
                <div class="col-sm-8">
                    <input id="syjzFmt" name="syjzFmt" type="hidden" th:field="*{syjzFmt}" >
                    <div id="syjzFmtEditor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">康熙字典：</label>
                <div class="col-sm-8">
                    <input id="kxzdFmt" name="kxzdFmt" type="hidden" th:field="*{kxzdFmt}" >
                    <div id="kxzdFmtEditor" class="summernote"></div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script src="/js/standalone.js"></script>
    <script src="/js/parser-html.js"></script>
    <script type="text/javascript">
        var prefix = ctx + "dict/dictspider";
        $("#form-dictspider-edit").validate({
            focusCleanup: true
        });

        function prettierFormat(html) {
            try{
                if(prettier == null || prettierPlugins == null) {
                  return html;
                }
                return prettier.format(html, {
                  parser: "html",
                  plugins: prettierPlugins
                });
            }catch(error){
               return html;
            }
        }


        $(function() {
			$('.summernote').summernote({
				placeholder : '请输入内容',
				height : 400,
				lang : 'zh-CN',
				followingToolbar : false,
				callbacks : {
					onImageUpload : function(files) {

					}
				}
			});
			var syjzFmt = $("#syjzFmt").val();
			$('#syjzFmtEditor').summernote('code', prettierFormat(syjzFmt));

			var kxzdFmt = $("#kxzdFmt").val();
			$('#kxzdFmtEditor').summernote('code', prettierFormat(kxzdFmt));
		});

        function submitHandler() {
            if ($.validate.form()) {

                var syjzFmt = $('#syjzFmtEditor').summernote('code');
				$("#syjzFmt").val(syjzFmt);

				var kxzdFmt = $('#kxzdFmtEditor').summernote('code');
				$("#kxzdFmt").val(kxzdFmt);

                $.operate.save(prefix + "/edit", $('#form-dictspider-edit').serialize());
            }
        }
    </script>
</body>
</html>